procedure TPlayScene.BeginScene();
var
  i, j, k, n, M, mmm, ix, iy, line, defx, defy, wunit, fridx, ani, anitick, ax, ay, idx: Integer;
  dsurface, D: TDXTexture;
  b, blend, movetick: Boolean;
  DropItem: pTDropItem;
  evn: TClEvent;
  Actor: TActor;
  meff: TMagicEff;
  ShowItem: pTShowItem;
  cc, nFColor, nBColor: Integer;
  tick, dwCheckTime: LongWord;
  boCheckTimeLimit: Boolean;
  DrawRect: TRect;
begin
  cc := 0;
  tick := GetTickCount();
  if (g_MySelf = nil) then
  begin
    exit;
  end;
  g_boDoFastFadeOut := False;

  movetick := False;
  if g_boSpeedRate then
  begin           //move speed
    if tick - m_dwMoveTime >= (95 - g_MoveSpeedRate div 2) then
    begin //move speed
      m_dwMoveTime := tick;
      movetick := True;
    end;
  end
  else
  begin
    if tick - m_dwMoveTime >= 95 then
    begin
      m_dwMoveTime := tick;
      movetick := True;
    end;
  end;

  if tick - m_dwAniTime >= 50 then
  begin //ز
    m_dwAniTime := tick;
    Inc(m_nAniCount);
    if m_nAniCount > 100000 then
      m_nAniCount := 0;
  end;

  try
    i := 0;
    while True do
    begin                 //DYNAMIC MODE
      if i >= m_ActorList.Count then
        Break;
      Actor := m_ActorList[i];
      if Actor.m_boDeath and g_gcGeneral[8] and not Actor.m_boItemExplore and (Actor.m_btRace <> 0) and Actor.IsIdle then
      begin
        Inc(i);
        Continue;
      end;

      if movetick then
        Actor.m_boLockEndFrame := False;

      if not Actor.m_boLockEndFrame then
      begin
        Actor.ProcMsg;
        if movetick then
        begin
          if Actor.Move() then
          begin
            m_boPlayChange := m_boPlayChange;
            Inc(i);
            Continue;
          end;
        end;
        Actor.Run;
        if Actor <> g_MySelf then
          Actor.ProcHurryMsg;
      end;
      if Actor = g_MySelf then
        Actor.ProcHurryMsg;

      //dogz....
      if Actor.m_nWaitForRecogId <> 0 then
      begin
        if Actor.IsIdle then
        begin
          DelChangeFace(Actor.m_nWaitForRecogId);
          NewActor(Actor.m_nWaitForRecogId, Actor.m_nCurrX, Actor.m_nCurrY, Actor.m_btDir, Actor.m_nWaitForFeature, Actor.m_nWaitForStatus);
          Actor.m_nWaitForRecogId := 0;
          Actor.m_boDelActor := True;
        end;
      end;
      if Actor.m_boDelActor then
      begin
        g_FreeActorList.Add(Actor);
        m_ActorList.Delete(i);
        if g_TargetCret = Actor then
          g_TargetCret := nil;
        if g_FocusCret = Actor then
          g_FocusCret := nil;
        if g_MagicTarget = Actor then
          g_MagicTarget := nil;
      end
      else
        Inc(i);
    end;
  except
    on E: Exception do
      DebugOutStr('101 ' + E.Message);
  end;
  m_boPlayChange := m_boPlayChange or (GetTickCount > m_dwPlayChangeTick);

  try                                   //STATIC MODE
    i := 0;
    while True do
    begin
      if i >= m_EffectList.Count then
        Break;
      meff := m_EffectList[i];
      if meff.m_boActive then
      begin
        if not meff.Run then
        begin
          meff.Free;                    //1003
          m_EffectList.Delete(i);
          Continue;
        end;
      end;
      Inc(i);
    end;

    i := 0;
    while True do
    begin
      if i >= m_FlyList.Count then
        Break;
      meff := m_FlyList[i];
      if meff.m_boActive then
      begin
        if not meff.Run then
        begin
          meff.Free;
          m_FlyList.Delete(i);
          Continue;
        end;
      end;
      Inc(i);
    end;

    EventMan.Execute;

    if (g_RareBoxWindow <> nil) then
    begin
      if g_RareBoxWindow.m_boActive then
      begin
        if not g_RareBoxWindow.Run then
          g_RareBoxWindow.m_boActive := False;
      end;
    end;
  except
    DebugOutStr('102');
  end;

  try
    ClearDropItemA();
 //ͷ¼ĵط
    if EventMan.EventList.Count > 0 then
    begin
      for k := 0 to EventMan.EventList.Count - 1 do
      begin
        evn := TClEvent(EventMan.EventList[k]);
        if (Abs(evn.m_nX - g_MySelf.m_nCurrX) > 16) or (Abs(evn.m_nY - g_MySelf.m_nCurrY) > 16) then
        begin
          evn.Free;
          EventMan.EventList.Delete(k);
          break;
        end;
      end;
    end;
  except
    DebugOutStr('103');
  end;

  try
    with Map.m_ClientRect do
    begin
      Left := g_MySelf.m_nRx - g_TileMapOffSetX;
      Right := g_MySelf.m_nRx + g_TileMapOffSetX;
      Top := g_MySelf.m_nRy - g_TileMapOffSetY;
      Bottom := g_MySelf.m_nRy + g_TileMapOffSetY;
    end;

    Map.UpdateMapPos(g_MySelf.m_nRx, g_MySelf.m_nRy);
  except
    on E: Exception do
      DebugOutStr('104 ' + E.Message);
  end;
end;
